# -*- coding: utf-8 -*-
"""
Created on Sun Jun 28 10:16:57 2020

@author: Administrator
"""


import numpy as np

import random

import copy



class OU_Noise(object):

    """Ornstein-Uhlenbeck process."""

    def __init__(self, size, seed, mu=0., theta=0.15, sigma=0.2):

        self.mu = mu * np.ones(size)

        self.theta = theta

        self.sigma = sigma

        self.seed = random.seed(seed)

        self.reset()



    def reset(self):

        """Reset the internal state (= noise) to mean (mu)."""

        self.state = copy.copy(self.mu)



    def sample(self):

        """Update internal state and return it as a noise sample."""

        dx = self.theta * (self.mu - self.state) + self.sigma * np.array([np.random.normal() for _ in range(len(self.state))])

        self.state += dx

        return self.state